package com.example.demo.service;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.example.demo.domain.Girl;
import com.example.demo.properties.GirlInterface;

@Service
public class GirlService {
	
	@Autowired
	private GirlInterface girlInterface;
	
	@Transactional
	public void insertTwo() {
		
		Girl girlA = new Girl();
		girlA.setAge(20);
		girlA.setSize("A");
		girlInterface.save(girlA);
		
		Girl girlB = new Girl();
		girlB.setAge(20);
		girlB.setSize("B");
		girlInterface.save(girlB);
		
	}
	
	public void getAge(Integer id) throws Exception {
		
		Girl girl=girlInterface.findOne(id);
		
		Integer age =girl.getAge();
		
		if(age<10) {
			throw new Exception("111");
		}else if(age>10&&age<16){
			throw new Exception("222");
		}
		
	}
}
